var e = require;
var t = module;
var o = exports;
var ii, nn = this && this.__extends || (ii = function (t, e) {
    return (ii = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        ii(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }
),
    rr = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        },
    ss = this && this.__generator ||
        function (t, e) {
            var o, i, n, a, r = {
                label: 0,
                sent: function () {
                    if (1 & n[0]) throw n[1];
                    return n[1]
                },
                trys: [],
                ops: []
            };
            return a = {
                next: s(0),
                throw: s(1),
                return: s(2)
            },
                "function" == typeof Symbol && (a[Symbol.iterator] = function () {
                    return this
                }),
                a;
            function s(t) {
                return function (e) {
                    return l([t, e])
                }
            }
            function l(a) {
                if (o) throw new TypeError("Generator is already executing.");
                for (; r;) try {
                    if (o = 1, i && (n = 2 & a[0] ? i.
                        return : a[0] ? i.
                            throw || ((n = i.
                                return) && n.call(i), 0) : i.next) && !(n = n.call(i, a[1])).done) return n;
                    switch (i = 0, n && (a = [2 & a[0], n.value]), a[0]) {
                        case 0:
                        case 1:
                            n = a;
                            break;
                        case 4:
                            return r.label++,
                            {
                                value: a[1],
                                done: !1
                            };
                        case 5:
                            r.label++,
                                i = a[1],
                                a = [0];
                            continue;
                        case 7:
                            a = r.ops.pop(),
                                r.trys.pop();
                            continue;
                        default: if (!(n = (n = r.trys).length > 0 && n[n.length - 1]) && (6 === a[0] || 2 === a[0])) {
                            r = 0;
                            continue
                        }
                            if (3 === a[0] && (!n || a[1] > n[0] && a[1] < n[3])) {
                                r.label = a[1];
                                break
                            }
                            if (6 === a[0] && r.label < n[1]) {
                                r.label = n[1],
                                    n = a;
                                break
                            }
                            if (n && r.label < n[2]) {
                                r.label = n[2],
                                    r.ops.push(a);
                                break
                            }
                            n[2] && r.ops.pop(),
                                r.trys.pop();
                            continue;
                    }
                    a = e.call(t, r)
                } catch (s) {
                    a = [6, s],
                        i = 0
                } finally {
                        o = n = 0
                    }
                if (5 & a[0]) throw a[1];
                return {
                    value: a[0] ? a[1] : void 0,
                    done: !0
                }
            }
        };
var oo = (this && this.__decorate) ||
    function (e, t, a, n) {
        var i,
            o = arguments.length,
            s = o < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, a)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);
        else
            for (var r = e.length - 1; r >= 0; r--)
                (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
        return o > 3 && s && Object.defineProperty(t, a, s), s;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var a = e("BaseModuleUI"),
    n = e("GlobalParams"),
    i = e("AssetsManager"),
    r = e("AudioManager"),
    s = e("CommonHelper"),
    l = e("ObjectPool"),
    _ = e("RoleSoldierInfo"),
    c = e("AD"),
    d = cc._decorator,
    h = d.ccclass,
    u = d.property,
    p = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.loading_bar = null),
                (t.loading_label = null),
                (t.hero_view = null),
                (t.left_pleyer_node = null),
                (t.right_player_node = null),
                (t.mode_type_sprite = null),
                t
            );
        }
        return (
            nn(t, e),
            (t.prototype.initView = function () {
                e.prototype.initView.call(this),
                    c.default.getInstance().hideBanner(),
                    r.default.getInstance().playFx("loading"),
                    this.uiManager.showTopView(!1),
                    (this.mode_type_sprite.spriteFrame = i.default
                        .getInstance()
                        .getModeInfoFrame("mode_type_" + n.GlobalParams.ChangeGameMode));
                var t = n.GlobalParams.GameHeroIndex.concat([]);
                t.splice(t.indexOf(n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex].role_id), 1);
                for (var o = 0; o < 2; o++) {
                    var a = s.default.getRandomInt(0, t.length - 1),
                        l = { hero_id: t[a], is_video: !0 };
                    n.GlobalParams.ReviveHeroInfo.push(l), t.splice(a, 1);
                }
                (n.GlobalParams.start_time = new Date().getTime()), this.showPlayerViewInfo(), this.changeScene();
            }),
            (t.prototype.changeScene = function () {
                return rr(this, void 0, void 0, function () {
                    var e = this;
                    return ss(this, function (t) {
                        switch (t.label) {
                            case 0:
                                return (
                                    this.setProgress(),
                                    this.setLabel("加载英雄资源。。。"),
                                    [4, i.default.getInstance().loadFightPrefabs("roles_prefabs")]
                                );
                            case 1:
                                return (
                                    t.sent(),
                                    this.setProgessOver(),
                                    this.setLabel("加载游戏资源。。。"),
                                    [4, i.default.getInstance().loadFightPrefabs("fight")]
                                );
                            case 2:
                                return (
                                    t.sent(),
                                    this.setProgessOver(),
                                    this.setLabel("加载音效资源。。。"),
                                    [4, i.default.getInstance().loadFightAudio("sound/fight_sound")]
                                );
                            case 3:
                                return (
                                    t.sent(),
                                    this.setProgessOver(),
                                    this.setLabel("加载游戏场景资源。。。"),
                                    cc.director.preloadScene("Fight", null, function (t) {
                                        t
                                            ? console.error("======场景加载错误========", t)
                                            : (l.default.getInstance().init(),
                                                e.unscheduleAllCallbacks(),
                                                cc
                                                    .tween(e.loading_bar)
                                                    .to(0.2, { width: 1280 })
                                                    .call(function () {
                                                        cc.director.loadScene("Fight");
                                                    })
                                                    .start());
                                    }),
                                    [2]
                                );
                        }
                    });
                });
            }),
            (t.prototype.setLabel = function (e) {
                this.loading_label.string = e;
            }),
            (t.prototype.setProgress = function () {
                var e = this;
                this.unscheduleAllCallbacks(),
                    (this.loading_bar.width = 0),
                    this.schedule(function () {
                        cc.tween(e.loading_bar)
                            .by(0.2, { width: 10 })
                            .call(function () {
                                e.loading_bar.width >= 1200 && e.unscheduleAllCallbacks();
                            })
                            .start();
                    }, 0.2);
            }),
            (t.prototype.setProgessOver = function () {
                var e = this;
                this.unscheduleAllCallbacks(),
                    cc
                        .tween(this.loading_bar)
                        .to(0.2, { width: 1280 })
                        .call(function () {
                            e.setProgress();
                        })
                        .start();
            }),
            (t.prototype.showPlayerViewInfo = function () {
                for (
                    var e = this,
                    t = function (t) {
                        var a = Math.floor(t / 2),
                            r = _.default.Role_info[n.GlobalParams.MatchGamePlayer[t].role_id],
                            s = t % 2 == 0 ? o.left_pleyer_node.children[a] : o.right_player_node.children[a];
                        (s.children[0].active = t == n.GlobalParams.MatchMyIndex),
                            (s.children[2].getComponent(cc.Sprite).spriteFrame = i.default
                                .getInstance()
                                .getHeroHeadFrame("hero_" + r.id)),
                            (s.children[3].getComponent(cc.Label).string =
                                "" + n.GlobalParams.MatchGamePlayer[t].name),
                            o.uiManager.getRoleSkele(r.id, function (o) {
                                (e.hero_view.children[t].children[0].getComponent(sp.Skeleton).skeletonData = o),
                                    e.hero_view.children[t].children[0]
                                        .getComponent(sp.Skeleton)
                                        .setAnimation(0, "battle_idle", !0);
                            }),
                            (o.hero_view.children[t].children[1].getComponent(cc.Label).string =
                                n.GlobalParams.MatchGamePlayer[t].name);
                    },
                    o = this,
                    a = 0;
                    a < 10;
                    a++
                )
                    t(a);
            }),
            oo([u(cc.Node)], t.prototype, "loading_bar", void 0),
            oo([u(cc.Label)], t.prototype, "loading_label", void 0),
            oo([u(cc.Node)], t.prototype, "hero_view", void 0),
            oo([u(cc.Node)], t.prototype, "left_pleyer_node", void 0),
            oo([u(cc.Node)], t.prototype, "right_player_node", void 0),
            oo([u(cc.Sprite)], t.prototype, "mode_type_sprite", void 0),
            oo([h], t)
        );
    })(a.default);
o.default = p;
